/*
 * Copyright 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ca.inrs.ete.app.shopx.images;

import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import ca.inrs.ete.app.shopx.R;

/**
 * A fragment representing a single page.
 */
public class ImagePageFragment extends Fragment {
	/**
	 * The argument key for the page number this fragment represents.
	 */
	public static final String ARG_INDEX    = "index";
	public static final String ARG_FILENAME = "file";

	/**
	 * The fragment's file name, which is set to the argument value for {@link #ARG_FILENAME}.
	 */
//	private ImageView   mImgView;		// provoke an OME
	private TouchExampleView   mImgView;
//	private com.sigseg.android.worldmap.WorldView mImgView;
	private Uri mFileName;

	/**
	 * Factory method for this fragment class. Constructs a new fragment for the given page number.
	 */
	public static ImagePageFragment create(int index, Uri fileName)
	{
		ImagePageFragment fragment = new ImagePageFragment();

		Bundle args = new Bundle();
		args.putInt(ARG_INDEX, index);
		args.putParcelable(ARG_FILENAME, fileName);
		fragment.setArguments(args);
		return fragment;
	}

	public ImagePageFragment() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mFileName = getArguments().getParcelable(ARG_FILENAME);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/*		Display through an ACTION_VIEW with MIME_TYPE "image/png"
		Intent viewIntent = new Intent(Intent.ACTION_VIEW);
		viewIntent.setDataAndType(DataProvider.CONTENT_URI_IMAGES, "image/png");
		startActivity(viewIntent);
*/
		View v = inflater.inflate(R.layout.fragment_image_page, null);
//		mImgView = (ImageView) v.findViewById(R.id.image_view); 	!! OME
		mImgView = (TouchExampleView) v.findViewById(R.id.image_view);
//		mImgView = (com.sigseg.android.worldmap.WorldView) v.findViewById(R.id.image_view);
		return v;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		// ImageView
//		mImgView.setImageURI(Uri.parse(mFileName));
		// TouchExampleView
		mImgView.setImageFile(mFileName);
		// WorldView
//		mImgView.setImageFile(mFileName.getPath());
	}

	/**
	 * Returns the file name represented by this fragment object.
	 */
	public Uri getFileName() {
		return mFileName;
	}
}


